/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package persistence;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * This class represents the our own entity manager factory
 * used to create the entity manager that will deal with
 * the JPA transactions.
 * 
 * @author Amigos do Noddy
 *
 */
public class MyEntityManagerFactory {
    private EntityManagerFactory emf;
    private static MyEntityManagerFactory instance = null;
    
    /**
     * Constructor
     */
    private MyEntityManagerFactory()
    {
    	try{
        emf = Persistence.createEntityManagerFactory("helpdeskPU");
    	}catch(Exception e)
    	{
    		e.printStackTrace();
    	}
    		
    }
    
    /**
     * Gets the singleton instance of this factory
     * @return sigleton instance
     */
    public static MyEntityManagerFactory getInstance()
    {
        if(instance == null)
            instance = new MyEntityManagerFactory();
        return instance;
    }
    
    /**
     * Creates the entity manager
     * @return entity manager
     */
    public EntityManager createEntityManager()
    {
        return emf.createEntityManager();
    }
    
    /**
     * Closes the factory 
     */
    public void close()
    {
        emf.close();
    }
    
    
}
